//
//  IMFCMModels.m
//  DualMediationSDK
//
//  Created by YeJary on 2025/6/23.
//

#import "IMFCMModels.h"

@implementation IMFCMRequest

+ (instancetype)requestWithAppId:(NSString *)appId 
                            uuid:(NSString *)uuid 
                        fcmToken:(NSString *)fcmToken {
    IMFCMRequest *request = [[IMFCMRequest alloc] init];
    request.app_id = appId;
    request.uuid = uuid;
    request.fcm_token = fcmToken;
    return request;
}

- (NSDictionary *)toDictionary {
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    if (self.app_id) {
        params[@"app_id"] = self.app_id;
    }
    
    if (self.uuid) {
        params[@"uuid"] = self.uuid;
    }
    
    if (self.fcm_token) {
        params[@"fcm_token"] = self.fcm_token;
    }
    
    return [params copy];
}

- (NSString *)description {
    return [NSString stringWithFormat:@"<%@: %p> app_id:%@ uuid:%@ fcm_token:%@",
            NSStringFromClass([self class]), self, self.app_id, self.uuid, self.fcm_token];
}

@end

@implementation IMFCMResponse

+ (instancetype)responseFromDictionary:(NSDictionary *)dictionary {
    if (!dictionary || ![dictionary isKindOfClass:[NSDictionary class]]) {
        return nil;
    }
    
    IMFCMResponse *response = [[IMFCMResponse alloc] init];
    response.code = [dictionary[@"code"] integerValue];
    response.message = dictionary[@"message"] ?: @"";
    response.data = dictionary[@"data"];
    response.trace_id = dictionary[@"trace_id"];
    
    return response;
}

- (BOOL)isSuccess {
    return self.code == 200;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"<%@: %p> code:%ld message:%@ data:%@ trace_id:%@",
            NSStringFromClass([self class]), self, (long)self.code, self.message, self.data, self.trace_id];
}

@end